//package com.example.ssyinitlearn.SpringSecurity;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.example.ssyinitlearn.entity.UsersEntity;
//import com.example.ssyinitlearn.service.UsersService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.AuthorityUtils;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
//@Service("UserDetailsService")
//public class MyUserDetailService implements UserDetailsService {
//
//    @Autowired
//    UsersService usersService;
//
//    /**
//     * Locates the user based on the username. In the actual implementation, the search
//     * may possibly be case sensitive, or case insensitive depending on how the
//     * implementation instance is configured. In this case, the <code>UserDetails</code>
//     * object that comes back may have a username that is of a different case than what
//     * was actually requested..
//     *
//     * @param username the username identifying the user whose data is required.
//     * @return a fully populated user record (never <code>null</code>)
//     * @throws UsernameNotFoundException if the user could not be found or the user has no
//     *                                   GrantedAuthority
//     */
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        UsersEntity user = usersService.getOne(new QueryWrapper<UsersEntity>().eq("username", username));
//        if (user == null) {
//            throw new UsernameNotFoundException("用户名不存在");
//        }
//        List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList("role");
//        return new User(user.getUsername(), new BCryptPasswordEncoder().encode(user.getPassword()), auths);
//    }
//}
